function isValid(str) {
    const map = {'(':')','[':']','{':'}'};
    const stack = [];
    for(let i=0;i<str.length;i++){
        let top = stack.length && stack[stack.length-1];
        if(top && map[top]==str[i]){
            stack.pop();
        }
        if(map[str[i]]){
            stack.push(str[i]);
        }
    }
    return stack.length==0;
}

console.log(isValid('sfsd(dsa[asf{d}a{d}]daf{dafa)}'))